package com.xyhuo.leetcode.june;

import com.xyhuo.leetcode.common.TreeNode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 199. 二叉树的右视图
 * https://leetcode.cn/problems/binary-tree-right-side-view/
 */
public class RightSideView {

    public List<Integer> rightSideView(TreeNode root) {
        search(0, root);
        List<Integer> ans = new ArrayList<>();
        for (int i = 0; i < map.size(); i++) {
            ans.add(map.get(i));
        }
        return ans;
    }

    Map<Integer, Integer> map = new HashMap<>();

    private void search(int step, TreeNode root) {
        if (null == root) {
            return;
        }
        map.put(step, root.val);
        search(step + 1, root.left);
        search(step + 1, root.right);
    }
}
